package com.luckyframe.project.jmeter.jmeterTaskScheduling.controller;

import com.luckyframe.common.utils.poi.ExcelUtil;
import com.luckyframe.framework.aspectj.lang.annotation.Log;
import com.luckyframe.framework.aspectj.lang.enums.BusinessType;
import com.luckyframe.framework.web.controller.BaseController;
import com.luckyframe.framework.web.domain.AjaxResult;
import com.luckyframe.framework.web.page.TableDataInfo;
import com.luckyframe.project.jmeter.jmeterTaskScheduling.domain.JmeterTaskScheduling;
import com.luckyframe.project.jmeter.jmeterTaskScheduling.service.IJmeterTaskSchedulingService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * jmeter测试计划调度 信息操作处理
 * 
 * @author lancelot
 * @date 2020-10-14
 */
@Controller
@RequestMapping("/jmeter/jmeterTaskScheduling")
public class JmeterTaskSchedulingController extends BaseController
{
    private String prefix = "jmeter/jmeterTaskScheduling";
	
	@Autowired
	private IJmeterTaskSchedulingService jmeterTaskSchedulingService;
	
	@RequiresPermissions("jmeter:jmeterTaskScheduling:view")
	@GetMapping()
	public String jmeterTaskScheduling()
	{
	    return prefix + "/jmeterTaskScheduling";
	}
	
	/**
	 * 查询jmeter测试计划调度列表
	 */
	@RequiresPermissions("jmeter:jmeterTaskScheduling:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(JmeterTaskScheduling jmeterTaskScheduling)
	{
		startPage();
        List<JmeterTaskScheduling> list = jmeterTaskSchedulingService.selectJmeterTaskSchedulingList(jmeterTaskScheduling);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出jmeter测试计划调度列表
	 */
	@RequiresPermissions("jmeter:jmeterTaskScheduling:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JmeterTaskScheduling jmeterTaskScheduling)
    {
    	List<JmeterTaskScheduling> list = jmeterTaskSchedulingService.selectJmeterTaskSchedulingList(jmeterTaskScheduling);
        ExcelUtil<JmeterTaskScheduling> util = new ExcelUtil<JmeterTaskScheduling>(JmeterTaskScheduling.class);
        return util.exportExcel(list, "jmeterTaskScheduling");
    }
	
	/**
	 * 新增jmeter测试计划调度
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存jmeter测试计划调度
	 */
	@RequiresPermissions("jmeter:jmeterTaskScheduling:add")
	@Log(title = "jmeter测试计划调度", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(JmeterTaskScheduling jmeterTaskScheduling)
	{		
		return toAjax(jmeterTaskSchedulingService.insertJmeterTaskScheduling(jmeterTaskScheduling));
	}

	/**
	 * 修改jmeter测试计划调度
	 */
	@GetMapping("/edit/{schedulingId}")
	public String edit(@PathVariable("schedulingId") Long schedulingId, ModelMap mmap)
	{
		JmeterTaskScheduling jmeterTaskScheduling = jmeterTaskSchedulingService.selectJmeterTaskSchedulingById(schedulingId);
		mmap.put("jmeterTaskScheduling", jmeterTaskScheduling);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存jmeter测试计划调度
	 */
	@RequiresPermissions("jmeter:jmeterTaskScheduling:edit")
	@Log(title = "jmeter测试计划调度", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(JmeterTaskScheduling jmeterTaskScheduling)
	{		
		return toAjax(jmeterTaskSchedulingService.updateJmeterTaskScheduling(jmeterTaskScheduling));
	}
	
	/**
	 * 删除jmeter测试计划调度
	 */
	@RequiresPermissions("jmeter:jmeterTaskScheduling:remove")
	@Log(title = "jmeter测试计划调度", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(jmeterTaskSchedulingService.deleteJmeterTaskSchedulingByIds(ids));
	}
	
}
